﻿using System.ComponentModel;
using System.ServiceModel.DomainServices.Client.ApplicationServices;

namespace RIBA.Helper
{
	/// <summary>
	/// For Blendability: if WebContext is created in App.Constructor (see following code) App_WebContext cannot be used in xaml in design mode
	///  var webContext = new WebContext { Authentication = new FormsAuthentication() }; 
	///  Resources.Add("App_WebContext", webContext);
	///  ApplicationLifetimeObjects.Add(webContext);
	/// 
	/// Usage: Text="{Binding Path=WebContext.Authentication.User.Name, Source={StaticResource App_WebContextWrapper}}"
	/// </summary>
	public class WebContextWrapper
	{
		private static WebContext _webContext;

		public WebContext WebContext
		{
			get { return _webContext; }
		}

		public WebContextWrapper()
		{
			if (_webContext != null)
				return;

			if (!DesignerProperties.IsInDesignTool)
				_webContext = new WebContext { Authentication = new FormsAuthentication() };
		}
	}
}
